<?php
$this->headTitle('Добро пожаловать в систему управления сайтом');


$this->headLink(array('href' => '/cms/styles/box.css', 'rel' => "stylesheet", 'type' => "text/css"));
$this->headLink(array('href' => '/cms/styles/menuTree.css', 'rel' => "stylesheet", 'type' => "text/css"));
$this->headLink(array('href' => '/cms/styles/popupMenu.css', 'rel' => "stylesheet", 'type' => "text/css"));
$this->headLink(array('href' => '/cms/styles/style.css', 'rel' => "stylesheet", 'type' => "text/css"));


$this->headScript(Zend_View_Helper_HeadScript::FILE,'/cms/scripts/dojo/dojo.js');
$this->headScript(Zend_View_Helper_HeadScript::FILE,'/cms/scripts/SimpleMenu.js');
$this->headScript(Zend_View_Helper_HeadScript::FILE,'/cms/scripts/ajaxLib.js');
$this->headScript(Zend_View_Helper_HeadScript::FILE,'/cms/scripts/Popup.js');
$this->headScript(Zend_View_Helper_HeadScript::FILE,'/cms/scripts/menuTree.js');
$this->headScript(Zend_View_Helper_HeadScript::FILE,'/cms/scripts/modalWin.js');
$this->headScript(Zend_View_Helper_HeadScript::FILE,'/cms/scripts/content.js');
$this->headScript(Zend_View_Helper_HeadScript::SCRIPT, <<<EOD

var current_menu_point = 1;

var mt = new menuTree();
// Затычка для корневого элемента
var rootEl = new Object();
rootEl.id = 0;
mt.branchCashe[0] = rootEl;
// ---------------------------------
mt.branchInitAdaptor = function (self) {

		self.submenuObj.innerHTML = 'Pending...';
		ajaxLib('/cms/menu/get/id/'+self.id,false,function (ret) {  self.submenuObj.innerHTML = ret })

	
		self.triggerObj.onmouseover = function () {
				self.triggerObj.src = self.collapsed==0 ? '/cms/images/closed-a.gif' : '/cms/images/opend-a.gif';
			}
			
		self.triggerObj.onmouseout = function () {
				self.triggerObj.src = self.collapsed==0 ? '/cms/images/closed.gif' : '/cms/images/opend.gif';
			}
		
		self.triggerObj.onclick = function() {
				if (self.collapsed==0) {
					self.triggerObj.src = '/cms/images/opend-a.gif';
					self.show();
				} else {
					self.triggerObj.src = '/cms/images/closed-a.gif';
					self.hide();
				}
			}
		
		try {
			if (typeof event=='object') {
				event.srcElement.fireEvent('on'+event.type);
			}
		} catch (e) {  }
		
	};
	
	
	
	
	
	
appendContextMenu = function (trigger,actions,cur_menu_id,root_menu_id) {

	var reloadBranchesFn = function(r) {
				if (r.toString().substring(0,1)=='y') {
					mt.reloadBranches(root_menu_id,0);
					
					ajaxLib('/cms/menu/ifexsists/id/'+current_menu_point,false,
						function (res) {
							var res = res.toString().substring(0,1);
							if (res=='y') {
								loadPath(current_menu_point);
							} else {
								gotopoint(root_menu_id);
							}
						});
						
				} else {
					alert('Сообщение: '+r);
				}
			},
		standartActions = {
				"add" : ['<img src="/cms/images/add.gif" width="16" height="16" align="absmiddle" />Новый раздел', function (menu_id) {
						
						shadowbox_callback = function () {
							reloadBranchesFn('y');
							shadowbox_callback = function () { };
						}
						
						
						Shadowbox.open({
						      player:     'iframe',
						      title:      '',
						      content:    '/cms/menu/addform/root_id/'+menu_id,
						      height:     330,
						      width:      550
						  });
						  
					} ],
				"up"  : ['<img src="/cms/images/move_up.gif" width="16" height="16" align="absmiddle" />Подвинуть вверх', function (menu_id) {
						ajaxLib('/cms/menu/move/direction/up/id/'+menu_id,false,reloadBranchesFn);
					} ],
				"down": ['<img src="/cms/images/move_down.gif" width="16" height="16" align="absmiddle" />Подвинуть вниз', function (menu_id) {
						ajaxLib('/cms/menu/move/direction/down/id/'+menu_id,false,reloadBranchesFn);
					} ],
				"edit" : ['<img src="/cms/images/edit.gif" width="16" height="16" align="absmiddle" />Изменить', function (menu_id) {
						
						shadowbox_callback = function () {
							reloadBranchesFn('y');
							shadowbox_callback = function () { };
						}
						
						Shadowbox.open({
						      player:     'iframe',
						      title:      '',
						      content:    '/cms/menu/editform/menu_id/'+menu_id,
						      height:     330,
						      width:      550
						  });
					} ],
				"del" : ['<img src="/cms/images/remove.gif" width="16" height="16" align="absmiddle" />Удалить', function (menu_id) {
						if (confirm('Вы подтверждаете удаление пункта меню?')) {	
							ajaxLib('/cms/menu/delete/id/'+menu_id,false,reloadBranchesFn);
						}
					} ],
				"properties" : ['<img src="/cms/images/gear.png" width="16" height="16" align="absmiddle" />Настройки', function (menu_id) {
						shadowbox_callback = function () {
							reloadBranchesFn('y');
							shadowbox_callback = function () { };
						}
						
						Shadowbox.open({
						      player:     'iframe',
						      title:      'Настройки раздела',
						      content:    '/cms/menu/propertiesform/menu_id/'+menu_id,
						      height:     250,
						      width:      400
						  });
					} ],
				"access": ['<img src="/cms/images/key.png" width="16" height="16" align="absmiddle" />Доступ', function (menu_id) {
						Shadowbox.open({
						      player:     'iframe',
						      title:      'Управление доступом',
						      content:    '/cms/administrator/menu/id/'+menu_id,
						      height:     600,
						      width:      700
						  });
					}]
			};
		
		
		
		var popupDiv = document.createElement('DIV');
		popupDiv.className = 'pupupMenu';
		document.body.appendChild(popupDiv);

		var pa = new PopupArea(trigger,popupDiv,PopupAreaAdaptors.SplashCursorCords);
		
		
		var menuListObj = document.createElement('UL');
		menuListObj.className = 'SystemMenu';
		
		var newMenu = new SimpleMenu(menuListObj);
		
		var applyAction = function (obj,mid,fn) {
				obj.onclick = function () {
					fn(mid);
					pa.do_hide(pa);
				};
		}
		
		for (var a=0;a<actions.length;a++) {
			var aObj = document.createElement('A');
			aObj.href = 'javascript:;';
			applyAction(aObj,cur_menu_id,standartActions[actions[a]][1]);
			aObj.innerHTML = standartActions[actions[a]][0];
			newMenu.add(aObj);
			
		}
		
		
		
		popupDiv.appendChild(menuListObj);
		
		
		trigger.onmouseover = function () { };
					
					
		
		/*trigger.onclick = function () {
				gotopoint(cur_menu_id);
			};
		trigger.href = 'javascript:;';*/
};


var appendPopupPathAction = function (event,trigger,target) {
	// данный скрипт производит мутацию событий на объекте. вызывает обект popupArea 
	// который навешивает собственные события и удаляет старые. 
	// в конце на обекте происходит вызов события

	if (typeof target == 'string') {
		target = document.getElementById(target);
	} 
	var ulElement = target.getElementsByTagName('UL');
	new SimpleMenu(ulElement[0]);
	
	var SplashPathMenuAdaptor = function (popupMenuObj) {
		popupMenuObj.triggerEl.onmouseover = function (e) {
				if (navigator.appName=='Netscape') {
					var popupLeft = e.clientX;
					var popupTop = e.clientY+popupMenuObj.triggerEl.height;
				} else {
					var popupLeft = event.clientX-event.offsetX;
					var popupTop = event.clientY+(popupMenuObj.triggerEl.height-event.offsetX);
				}
				popupMenuObj.areaEl.style.left = popupLeft+'px';
				popupMenuObj.areaEl.style.top  = popupTop+'px';
				popupMenuObj.show(popupMenuObj);
			};
			
		popupMenuObj.triggerEl.onmouseout = function () { popupMenuObj.hide(popupMenuObj) };
		popupMenuObj.areaEl.onmouseover = function () { popupMenuObj.show(popupMenuObj) };
		popupMenuObj.areaEl.onmouseout = function () { popupMenuObj.hide(popupMenuObj) };
		
	}
	
	new PopupArea(trigger,target,SplashPathMenuAdaptor);
	
	
	if (navigator.appName=="MSIE" || navigator.appName.indexOf('Microsoft')!='-1') {
		trigger.fireEvent('onmouseover');
	} else {
		var ent = document.createEvent('MouseEvents');
		ent.initMouseEvent('mouseover', true, true, window, 1, event.screenX, event.screenY, event.clientX, event.clientY, false, false, false, false, 0, null);
		trigger.dispatchEvent(ent);
	}
}



var gotopoint = function(cur_menu_id) {
	current_menu_point = cur_menu_id;
	loadPath(cur_menu_id);
	
	ajaxLib('/cms/template/index/menu_id/'+cur_menu_id,false,
		function (r) {
			document.getElementById('templateArea').innerHTML = r;
		});

		
	dojo.xhrGet({
	    url: "/cms/menu/info/menu_id/"+cur_menu_id,
	    load: function(responseObject, ioArgs){
	      
		    actions = responseObject.avlible_actions;
		    root_menu_id = responseObject.root_menu_id;
		      
	      return responseObject;
	    },
	    error: function(response, ioArgs){
	      alert("An error occurred, with response: " + response);
	      return response;
	    },
	    handleAs: "json",
	    sync: true
	  });
	
	var 
		reloadBranchesFn = function(r) {
				if (r.toString().substring(0,1)=='y') {
					mt.reloadBranches(root_menu_id,0);
					
					ajaxLib('/cms/menu/ifexsists/id/'+current_menu_point,false,
						function (res) {
							var res = res.toString().substring(0,1);
							if (res=='y') {
								loadPath(current_menu_point);
							} else {
								gotopoint(root_menu_id);
							}
						});
						
				} else {
					alert('Сообщение: '+r);
				}
			},
		standartActions = {
				"add" : ['<img src="/cms/images/add.gif" width="16" height="16" align="absmiddle" />Новый раздел', function (menu_id) {
						
						shadowbox_callback = function () {
							reloadBranchesFn('y');
							shadowbox_callback = function () { };
						}
						
						Shadowbox.open({
						      player:     'iframe',
						      title:      '',
						      content:    '/cms/menu/addform/root_id/'+menu_id,
						      height:     400,
						      width:      550
						  });
						  
					} ],
				"up"  : ['<img src="/cms/images/move_up.gif" width="16" height="16" align="absmiddle" />Подвинуть вверх', function (menu_id) {
						ajaxLib('/cms/menu/move/direction/up/id/'+menu_id,false,reloadBranchesFn);
					} ],
				"down": ['<img src="/cms/images/move_down.gif" width="16" height="16" align="absmiddle" />Подвинуть вниз', function (menu_id) {
						ajaxLib('/cms/menu/move/direction/down/id/'+menu_id,false,reloadBranchesFn);
					} ],
				"edit" : ['<img src="/cms/images/edit.gif" width="16" height="16" align="absmiddle" />Изменить', function (menu_id) {
						
						shadowbox_callback = function () {
							reloadBranchesFn('y');
							shadowbox_callback = function () { };
						}
						
						Shadowbox.open({
						      player:     'iframe',
						      title:      '',
						      content:    '/cms/menu/editform/menu_id/'+menu_id,
						      height:     330,
						      width:      550
						  });
					} ],
				"del" : ['<img src="/cms/images/remove.gif" width="16" height="16" align="absmiddle" />Удалить', function (menu_id) {
						if (confirm('Вы подтверждаете удаление пункта меню?')) {	
							ajaxLib('/cms/menu/delete/id/'+menu_id,false,reloadBranchesFn);
						}
					} ],
				"properties" : ['<img src="/cms/images/gear.png" width="16" height="16" align="absmiddle" />Настройки', function (menu_id) {
						shadowbox_callback = function () {
							reloadBranchesFn('y');
							shadowbox_callback = function () { };
						}
						
						Shadowbox.open({
						      player:     'iframe',
						      title:      'Настройки раздела',
						      content:    '/cms/menu/propertiesform/menu_id/'+menu_id,
						      height:     250,
						      width:      400
						  });
					} ],
				"link" : ['<img src="/cms/images/chain.png" width="16" height="16" align="absmiddle" />Ссылка', function (menu_id) {
						Shadowbox.open({
						      player:     'iframe',
						      title:      'Ссылка на раздел',
						      content:    '/cms/menu/showlink/menu_id/'+menu_id,
						      height:     200,
						      width:      400
						  });
					} ],
				"access": ['<img src="/cms/images/key.png" width="16" height="16" align="absmiddle" />Доступ', function (menu_id) {
						Shadowbox.open({
						      player:     'iframe',
						      title:      'Управление доступом',
						      content:    '/cms/administrator/menu/id/'+menu_id,
						      height:     600,
						      width:      700
						  });
					}]
					
			};
		
	
	var toolbarListObj = document.createElement('UL');
	toolbarListObj.className = 'SystemMenu';
	
	var applyAction = function (obj,mid,fn) {
			obj.onclick = function () {
				fn(mid);
				//pa.do_hide(pa);
			};
	}
	
	for (var a=0;a<actions.length;a++) {
		var taObj = document.createElement('A');
		taObj.href = 'javascript:;';
		applyAction(taObj,cur_menu_id,standartActions[actions[a]][1]);
		taObj.innerHTML = standartActions[actions[a]][0];
		
		liObj = document.createElement('LI');
		liObj.appendChild(taObj);
		toolbarListObj.appendChild(liObj);
	}
	
	
	document.getElementById('pageToolbar').style.display = '';
	document.getElementById('pageToolbar').innerHTML = '';
	document.getElementById('pageToolbar').appendChild(toolbarListObj);
}

var loadPath = function(menu_id) {
		ajaxLib('/cms/menu/path/id/'+menu_id,false,
		function (r) {
			document.getElementById('pathBox').innerHTML = r;
		});
	}
	

	

	
var placeholderActions = new Object;

placeholderActions.reload = function (placeholder_id) {
		ajaxLib('/cms/placeholder/index/id/'+placeholder_id,false,
			function (r) {
					document.getElementById('placeholder_'+placeholder_id).innerHTML = r;
				});
	}

placeholderActions.add = function (placeholder_id) {
		shadowbox_callback = function () {
				placeholderActions.reload(placeholder_id);
				shadowbox_callback = function () { };
			}
			
		Shadowbox.open({
		      player:     'iframe',
		      title:      'Добавление контента',
		      content:    '/cms/placeholder/add/id/'+placeholder_id,
		      height:     300,
		      width:      550
		  });
	}

placeholderActions.action = function (placeholder_id,type,placeholder_content_id) {
		var act_confrim = true;
		if (type=='del') {
			act_confrim = confirm('Удалить контент из блока?');
		}
		if (act_confrim) {
			ajaxLib('/cms/placeholder/index/id/'+placeholder_id+'/act/'+type+'/cid/'+placeholder_content_id,false,
			function (r) {
					document.getElementById('placeholder_'+placeholder_id).innerHTML = r;
				});
		}
	}
	
placeholderActions.geoLink = function (ph_id,content_id) {
		Shadowbox.open({
		      player:     'iframe',
		      title:      'Редактирование привязки по гео-признаку',
		      content:    '/cms/placeholder/geo/ph_id/'+ph_id+'/content_id/'+content_id,
		      height:     350,
		      width:      350
		  });
	}
EOD
);


//$this->headScript(Zend_View_Helper_HeadScript::FILE,'/cms/scripts/shadowbox/build/adapter/shadowbox-base.js');
//$this->headScript(Zend_View_Helper_HeadScript::FILE,'/cms/scripts/shadowbox/build/shadowbox.js');

$this->headLink(array('href' => '/cms/scripts/shadowbox-3.0rc1/shadowbox.css', 'rel' => "stylesheet", 'type' => "text/css"));
$this->headScript(Zend_View_Helper_HeadScript::FILE,'/cms/scripts/shadowbox-3.0rc1/shadowbox.js');

$this->headScript(Zend_View_Helper_HeadScript::SCRIPT, <<<EOD
var shadowbox_callback = function () {};

reset_shadowbox_callback = function () {
	shadowbox_callback = function () {};
} 

Shadowbox.init({
    players:    ['html', 'iframe', 'img', 'swf'],
    onClose: function() { shadowbox_callback() }
});
	
window.onload = function(){
    
	gotopoint(1);

};
EOD
);
$this->layout()->body_attr = 'oncontextmenu="return false"';
?>


<div id="header">
  <div id="logoPlace"><img src="/cms/images/mf-logo.jpg" width="55" height="32" /></div>
  <div id="pathPlace">
    <div id="pathBox"></div>
  </div>
</div>
<div id="navigation">
  <div id="navigaionBox">
        <div class="menuItem"><img src="/cms/images/closed.gif" width="8" height="17" align="absmiddle" id="trigger1" onmouseover="mt.initBranch(1,0,this,'menu1')" /><img src="/cms/images/crown.gif" width="16" height="16" border="0" align="absmiddle" /><a href="javascript:;" onclick="gotopoint(1)" <?= CmsAccess::checkMenu(1) && CmsAccess::checkModule('menu') ? "onmouseover=\"appendContextMenu(this,['add'".(CmsAccess::checkModule('administrators') ? ",'access'" : "")."],1,0)\"" : "" ?>>Главная</a></div>
        <div class="subMenuList" id="menu1"></div>
        <div class="menuItem"><img src="/cms/images/closed.gif" width="8" height="17" align="absmiddle" id="trigger2" onmouseover="mt.initBranch(2,0,this,'menu2')" /><img src="/cms/images/folder.png" width="16" height="16" border="0" align="absmiddle" /><a href="javascript:;" onclick="gotopoint(2)" <?= CmsAccess::checkMenu(2) && CmsAccess::checkModule('menu') ? "onmouseover=\"appendContextMenu(this,['add'".(CmsAccess::checkModule('administrators') ? ",'access'" : "")."],2,0)\"" : "" ?>>Дополнительное меню</a></div>
        <div class="subMenuList" id="menu2"></div> 
        <!-- 
        <div class="menuItem"><img src="/cms/images/dot.gif" width="8" height="17" /><img src="/cms/images/clock.gif" width="16" height="16" align="absmiddle" /><a href="#">Журнал</a></div>
        <div class="menuItem"><img src="/cms/images/dot.gif" width="8" height="17" /><img src="/cms/images/gear.gif" width="16" height="16" align="absmiddle" /><a href="#">Настройки сайта</a></div>
         -->
        <?php if (CmsAccess::checkModule('users')): ?><div class="menuItem"><img src="/cms/images/dot.gif" width="8" height="17" /><img src="/cms/images/user.png" width="16" height="16" align="absmiddle" /><a href="/cms/users"  rel="shadowbox;title=Список пользователей;height=600;width=1000;player=iframe">Пользователи</a></div><?php endif; ?>
        <?php if (CmsAccess::checkModule('orders')): ?><div class="menuItem"><img src="/cms/images/dot.gif" width="8" height="17" /><img src="/cms/images/orders.png" width="16" height="16" align="absmiddle" /><a href="/cms/orders"  rel="shadowbox;title=Заказы;height=640;width=1000;player=iframe">Заказы</a></div><?php endif; ?>
        <?php if (CmsAccess::checkModule('geofilter')): ?><div class="menuItem"><img src="/cms/images/dot.gif" width="8" height="17" /><img src="/cms/images/page_url.gif" width="16" height="16" align="absmiddle" /><a href="/cms/geo"  rel="shadowbox;title=Изменение списка гео-признаков;height=400;width=400;player=iframe">Географический фильтр</a></div><?php endif; ?>
        <?php if (CmsAccess::checkModule('voite')): ?><div class="menuItem"><img src="/cms/images/dot.gif" width="8" height="17" /><img src="/cms/images/star.png" width="16" height="16" align="absmiddle" /><a href="/cms/votes"  rel="shadowbox;title=Редактирование листа голосований;height=550;width=700;player=iframe">Голосования</a></div><?php endif; ?>
        <?php if (CmsAccess::checkModule('administrators')): ?><div class="menuItem"><img src="/cms/images/dot.gif" width="8" height="17" /><img src="/cms/images/administrator.png" width="16" height="16" align="absmiddle" /><a href="/cms/administrator"  rel="shadowbox;title=Редактирование списков администраторов и групп;height=550;width=700;player=iframe">Администраторы</a></div><?php endif; ?>
</div>
</div>
<div id="content">
  <div id="contentBox">
    <div>
      <div id="pageToolbar"></div>
      <div id="templateArea"></div>
    </div>
  </div>
</div>
